package vip.lsjscl.flowboot.workflow.entity;

import jakarta.persistence.*;
import lombok.Data;
import org.hibernate.annotations.Comment;
import vip.lsjscl.flowboot.util.constants.ActivityStatus;
import vip.lsjscl.flowboot.util.constants.ActivityType;
import vip.lsjscl.flowboot.util.constants.ExecutionLogic;
import vip.lsjscl.flowboot.util.converter.ActivityStatusConverter;
import vip.lsjscl.flowboot.util.converter.ListConverter;
import vip.lsjscl.flowboot.util.converter.OperationsConverter;
import vip.lsjscl.flowboot.workflow.model.NodeData;

import java.util.List;

/**
 * 活动
 * 描述工作流各个节点（活动）的配置信息
 * 例如节点名称、对应页面、允许的操作等
 *
 * @author zhangxingju
 * @date 2025/02/13
 */
@Data
@Entity
@Table(name = "dk_activity", indexes = {
        @Index(name = "idx_activity_workflow_version", columnList = "workflow_version_id"),
        @Index(name = "idx_activity_node_id", columnList = "node_id")
})
public class DKActivity extends BaseEntity {

    @Comment("用于关联前端 JSON 中的节点 ID")
    @Column(name = "node_id")
    private String nodeId;

    @Comment("活动名称")
    @Column(name = "name")
    private String name;

    @Comment("编码")
    @Column(name = "code")
    private String code;

    @Enumerated(value = EnumType.STRING)
    @Comment("类型(网关|活动)")
    @Column(name = "type")
    private ActivityType type;

    @Enumerated(value = EnumType.STRING)
    @Comment("执行逻辑")
    @Column(name = "execution_logic")
    private ExecutionLogic executionLogic = ExecutionLogic.ANY;

    @Comment("审核页面地址")
    @Column(name = "page_url")
    private String pageUrl;

    @Comment("激活时的loader")
    @Column(name = "before_class")
    private String beforeClass;

    @Comment("执行后的loader")
    @Column(name = "after_class")
    private String afterClass;

    // 为简单起见，将 List 类型转换为逗号分隔字符串存储（实际业务中可采用 join table 方式）
    @Comment("处理人")
    @Column(name = "approvers", columnDefinition = "longtext")
    @Convert(converter = ListConverter.class)
    private List<String> approvers;

    @Comment("处理部门")
    @Column(name = "departments", columnDefinition = "longtext")
    @Convert(converter = ListConverter.class)
    private List<String> departments;

    @Comment("操作集合")
    @Column(name = "operations", columnDefinition = "longtext")
    @Convert(converter = OperationsConverter.class)
    private List<NodeData.Operation> operations;

    @Comment("流程版本ID")
    @Column(name = "workflow_version_id")
    private String workflowVersionId;

    @Convert(converter = ActivityStatusConverter.class)
    @Comment("活动状态，如待办理(10)或已办理(20)")
    @Column(name = "status", columnDefinition = "int")
    private ActivityStatus status = ActivityStatus.NOT_ACTIVATED;

    @Comment("业务ID")
    @Column(name = "business_id")
    private String businessId;
} 